﻿package mortal.game.view.playerSystem
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.fashion.*;
    import mortal.game.view.mount.*;
    import mortal.game.view.mount.data.*;
    import mortal.game.view.mount.panel.*;
    import mortal.game.view.palyer.data.*;
    import mortal.game.view.palyer.util.*;
    import mortal.game.view.palyer.view.*;
    import mortal.game.view.petNew.*;
    import mortal.game.view.petNew.view.*;
    import mortal.game.view.shop.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PlayerSystemModule extends BaseWindow
    {
        private var _tabData:Array;
        private var _tabBars:GTileList;

        public function PlayerSystemModule(param1:ILayer = null)
        {
            this._tabData = new Array();
            super(LayerManager.windowLayer3D);
            setSize(766, 580);
            return;
        }// end function

        public function updateTabData(param1:DataProvider) : void
        {
            this._tabBars.dataProvider = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabBars = UIFactory.tileList(-84, 50, 100, 540, this);
            this._tabBars.columnWidth = 92;
            this._tabBars.rowHeight = 43;
            this._tabBars.horizontalGap = 3;
            this._tabBars.verticalGap = 0;
            this._tabBars.setStyle("cellRenderer", PlayerTabCellRender);
            this._tabBars.configEventListener(Event.CHANGE, this.onTabBarChangeHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._tabBars.dispose(param1);
            this._tabBars = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onTabBarChangeHandler(event:Event = null) : void
        {
            var _loc_2:PlayerTabData = null;
            if (this._tabBars.selectedIndex > (this._tabBars.length - 1))
            {
                this._tabBars.selectedIndex = 0;
            }
            _loc_2 = this._tabBars.getItemAt(this._tabBars.selectedIndex) as PlayerTabData;
            title = _loc_2.tabName;
            Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleTabChange, _loc_2));
            return;
        }// end function

        public function changeSelectIndex(param1:int) : void
        {
            this._tabBars.selectedIndex = param1;
            this.onTabBarChangeHandler();
            return;
        }// end function

        override protected function onWindowDownHandler(event:MouseEvent) : void
        {
            super.onWindowDownHandler(event);
            if (BuyGiftItemWin.isViewShow)
            {
                BuyGiftItemWin.instance.layer.setTop(BuyGiftItemWin.instance);
            }
            return;
        }// end function

        override protected function onMouseMoveHandler(event:MouseEvent) : void
        {
            super.onMouseMoveHandler(event);
            if (MountAvtivityWin.isViewShow())
            {
                MountAvtivityWin.instance.x = this.x + this.width + 4;
                MountAvtivityWin.instance.y = this.y + 37;
            }
            else if (PetActivityPanel.hasInstance() && PetActivityPanel.instance.isHide == false)
            {
                PetActivityPanel.instance.x = this.x + this.width + 4;
                PetActivityPanel.instance.y = this.y + 37;
            }
            else if (FashionActivityWin.hasInstance() && !FashionActivityWin.instance.isHide)
            {
                FashionActivityWin.instance.x = this.x + this.width + 4;
                FashionActivityWin.instance.y = this.y + 37;
            }
            if (BuyGiftItemWin.isViewShow)
            {
                BuyGiftItemWin.instance.x = this.x + this.width + 5;
                BuyGiftItemWin.instance.y = this.y - 3;
            }
            if (ChargeActivityWin.isViewShow)
            {
                ChargeActivityWin.instance.x = this.x + this.width + 8;
                ChargeActivityWin.instance.y = this.y;
            }
            return;
        }// end function

        override public function hide() : void
        {
            var _loc_2:BlessData = null;
            var _loc_3:MountData = null;
            var _loc_4:SPublicPet2 = null;
            var _loc_5:TMountConfig = null;
            var _loc_6:BlessData = null;
            var _loc_7:int = 0;
            var _loc_8:FashionAdvanceData = null;
            var _loc_9:String = null;
            var _loc_10:Date = null;
            var _loc_11:int = 0;
            if (BlessClearWin.isViewShow())
            {
                BlessClearWin.instance.wiggle();
                return;
            }
            var _loc_1:* = GameController.playerSystem.currentContoller;
            if (_loc_1)
            {
                if (_loc_1 is MountController)
                {
                    _loc_3 = Cache.instance.mount.mountData;
                    if (!BlessClearWin.winOpenRecortDic[Language.getString(35344)] && _loc_3.tMountConfig.blessClear && _loc_3.sPublicMount.bless > 0)
                    {
                        if (BlessClearWin.instance.isHide)
                        {
                            _loc_2 = new BlessData();
                            _loc_2.bless = _loc_3.sPublicMount.bless;
                            _loc_2.blessClear = _loc_3.tMountConfig.blessClear;
                            _loc_2.leftSeconds = (_loc_3.sPublicMount.lastAdvanceSuccessDt.time - ClockManager.instance.nowDate.time) * 0.001;
                            _loc_2.maxBless = _loc_3.tMountConfig.blessMax;
                            _loc_2.type = Language.getString(35344);
                            BlessClearWin.instance.show();
                            BlessClearWin.instance.blessData = _loc_2;
                            BlessClearWin.instance.callBack = this.callBack;
                            return;
                        }
                    }
                }
                else if (_loc_1 is NewPetController)
                {
                    _loc_4 = Cache.instance.newPet.pet;
                    _loc_5 = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypePet, _loc_4.code);
                    if (!BlessClearWin.winOpenRecortDic[Language.getString(35345)] && _loc_5.blessClear && _loc_4.bless > 0)
                    {
                        if (BlessClearWin.instance.isHide)
                        {
                            _loc_6 = new BlessData();
                            _loc_6.bless = _loc_4.bless;
                            _loc_6.blessClear = _loc_5.blessClear;
                            _loc_6.leftSeconds = (_loc_4.blessExpiredDt.time - ClockManager.instance.nowDate.time) * 0.001;
                            _loc_6.maxBless = _loc_5.blessMax;
                            _loc_6.type = Language.getString(35345);
                            BlessClearWin.instance.show();
                            BlessClearWin.instance.blessData = _loc_6;
                            BlessClearWin.instance.callBack = this.callBack;
                            return;
                        }
                    }
                }
                else if (_loc_1 is FashionController)
                {
                    _loc_7 = FashionController.FashionType;
                    _loc_8 = Cache.instance.fashion.getFashionInfo(_loc_7);
                    _loc_9 = FashionUtil.getFashionNameByType(_loc_7);
                    if (_loc_8.advanceInfo)
                    {
                        if (!BlessClearWin.winOpenRecortDic[_loc_9] && _loc_8.baseInfo.blessClear && _loc_8.advanceInfo.bless > 0)
                        {
                            if (BlessClearWin.instance.isHide)
                            {
                                _loc_2 = new BlessData();
                                _loc_2.bless = _loc_8.advanceInfo.bless;
                                _loc_2.blessClear = _loc_8.baseInfo.blessClear;
                                _loc_10 = ClockManager.instance.nowDate;
                                _loc_11 = Cache.instance.fashion.getFashionExpiredTime(_loc_8.type) - _loc_10.time / 1000;
                                if (_loc_11 > 0)
                                {
                                    _loc_2.leftSeconds = _loc_11;
                                }
                                _loc_2.maxBless = _loc_8.baseInfo.blessMax;
                                _loc_2.type = _loc_9;
                                BlessClearWin.instance.show();
                                BlessClearWin.instance.blessData = _loc_2;
                                BlessClearWin.instance.callBack = this.callBack;
                                return;
                            }
                        }
                    }
                }
            }
            super.hide();
            return;
        }// end function

        private function callBack(param1:int) : void
        {
            if (param1 == BlessClearWin.BlessBtnTypeOk)
            {
            }
            else if (param1 == BlessClearWin.BlessBtnTypeCacel)
            {
                super.hide();
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            PopupManager.closeAllFullView();
            return;
        }// end function

    }
}
